package hot100;

public class productExceptSelf3 {
    public int[] productExceptSelf(int[] nums) {
        //使用前缀积和后缀积
        int n = nums.length;
        int[] pre = new int[n];
        int[] aft = new int[n];
        //返回值
        int[] ret = new int[n];
        pre[0] = 1;
        aft[n - 1] = 1;
        for(int i = 1,j = n - 2;i < n;i++,j--) {
            pre[i] = pre[i - 1] * nums[i - 1];
            aft[j] = aft[j + 1] * nums[j + 1];
        }
        for(int i = 0;i < n;i++) {
            ret[i] = aft[i] * pre[i];
        }
        return ret;


    }
}
